home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / SeaInvaders.dxr / 00005_Particle Engine.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  5.2 KB  |  141 lines

  1. global bgOffset
  2.  
  3. on init_ParticleConstants
  4.   global p_StartSprite, p_MaxParticles, p_MaxFrames, p_FrameDelay, p_FrameTitle, p_StartFade, p_FadeIncrement, p_InkType, p_SpawnTimer, p_lockParticles, p_LockPic, p_StartSize, p_ScaleRate, p_RotatePic, p_DriftType
  5.   p_StartSprite = 150
  6.   p_MaxParticles = 100
  7.   p_MaxFrames = [3, 3, 3, 4]
  8.   p_FrameDelay = [6, 16, 10, 1]
  9.   p_DriftType = [1, 2, 2, 0]
  10.   p_FrameTitle = ["Bubble", "Bubble", "Bubble", "Laser"]
  11.   p_StartFade = 100
  12.   p_FadeIncrement = 1
  13.   p_InkType = 36
  14.   p_SpawnTimer = 0
  15.   p_RandomFlip = 0
  16.   p_RotatePic = 1
  17.   p_LockPic = 0
  18.   p_StartSize = point(6, 15)
  19.   p_ScaleRate = point(0, 0)
  20.   if p_FrameDelay < 1 then
  21.     p_FrameDelay = 1
  22.   end if
  23.   if p_StartFade < 1 then
  24.     p_StartFade = 1
  25.   end if
  26.   if p_StartFade > 100 then
  27.     p_StartFade = 100
  28.   end if
  29.   p_lockParticles = 1
  30. end
  31.  
  32. on init_Particles
  33.   global p_StartSprite, p_MaxParticles, p_MaxFrames, p_FrameDelay, p_FrameTitle, p_StartFade, p_FadeIncrement, p_InkType, p_SpawnTimer, particleData
  34.   particleData = []
  35.   repeat with wEntry = 1 to p_MaxParticles
  36.     wSprite = p_StartSprite + wEntry - 1
  37.     add(particleData, [0, 0, 0, point(0, 0), point(0, 0), point(0, 0)])
  38.     sprite(wSprite).visible = 0
  39.     puppetSprite(wSprite, 1)
  40.     set the member of sprite wSprite to p_FrameTitle[1] & " 1"
  41.     set the ink of sprite wSprite to p_InkType
  42.     set the loc of sprite wSprite to point(0, 0)
  43.     sprite(wSprite).locZ = 11
  44.   end repeat
  45. end
  46.  
  47. on addparticle spawnPoint, SpawnRotate, spawnType
  48.   global p_StartSprite, p_MaxParticles, p_MaxFrames, p_FrameDelay, p_FrameTitle, p_StartFade, p_FadeIncrement, p_InkType, p_SpawnTimer, p_RotatePic, particleData, p_lockParticles, p_DriftType
  49.   if p_lockParticles = 1 then
  50.     validSlot = 0
  51.     repeat with wSlot = 1 to p_MaxParticles
  52.       if (validSlot = 0) and (particleData[wSlot][1] = 0) then
  53.         validSlot = wSlot
  54.       end if
  55.     end repeat
  56.     if validSlot <> 0 then
  57.       case spawnType of
  58.         1:
  59.           mAim = random(360)
  60.           rPow = 5 + random(5)
  61.           locY = cos(mAim * PI / 180) * -rPow
  62.           locX = sin(mAim * PI / 180) * rPow
  63.         2:
  64.           if SpawnRotate = VOID then
  65.             SpawnRotate = random(360)
  66.           end if
  67.           rPow = random(100)
  68.           locY = cos(SpawnRotate * PI / 180) * -rPow
  69.           locX = sin(SpawnRotate * PI / 180) * rPow
  70.         3:
  71.           if SpawnRotate = VOID then
  72.             SpawnRotate = random(180) - 90
  73.           end if
  74.           rPow = random(50)
  75.           locY = cos(SpawnRotate * PI / 180) * -rPow
  76.           locX = sin(SpawnRotate * PI / 180) * rPow
  77.       end case
  78.       particleData[validSlot] = [spawnType, 0, 0, spawnPoint, point(locX, locY), point(0, 0)]
  79.       wSprite = p_StartSprite + validSlot - 1
  80.       set the loc of sprite wSprite to spawnPoint + bgOffset
  81.       set the member of sprite wSprite to p_FrameTitle[spawnType] & " 1"
  82.       set the blend of sprite wSprite to p_StartFade
  83.       sprite(wSprite).rotation = SpawnRotate
  84.       sprite(wSprite).visible = 1
  85.     end if
  86.   end if
  87. end
  88.  
  89. on moveParticles
  90.   global p_StartSprite, p_MaxParticles, p_MaxFrames, p_FrameDelay, p_FrameTitle, p_StartFade, p_FadeIncrement, p_InkType, p_SpawnTimer, p_LockPic, p_StartSize, p_ScaleRate, particleData, playerViewPoint, p_DriftType
  91.   p_SpawnTimer = p_SpawnTimer + 1
  92.   if p_SpawnTimer > 36500 then
  93.     p_SpawnTimer = 1
  94.   end if
  95.   repeat with wEntry = 1 to p_MaxParticles
  96.     wSprite = p_StartSprite + wEntry - 1
  97.     if particleData[wEntry][1] <> 0 then
  98.       eType = particleData[wEntry][1]
  99.       if particleData[wEntry][3] <= 1 then
  100.         particleData[wEntry][3] = p_FrameDelay[eType]
  101.         particleData[wEntry][2] = particleData[wEntry][2] + 1
  102.         if particleData[wEntry][2] > p_MaxFrames[eType] then
  103.           particleData[wEntry][1] = 0
  104.           sprite(wSprite).visible = 0
  105.         else
  106.           if p_LockPic = 0 then
  107.             set the member of sprite wSprite to p_FrameTitle[eType] & " " & string(particleData[wEntry][2])
  108.           else
  109.             set the blend of sprite wSprite to p_StartFade + (p_FadeIncrement * particleData[wEntry][2])
  110.           end if
  111.         end if
  112.       else
  113.         case p_DriftType[eType] of
  114.           1:
  115.             if particleData[wEntry][5][1] > 0 then
  116.               particleData[wEntry][6][1] = particleData[wEntry][6][1] - 1
  117.             else
  118.               particleData[wEntry][6][1] = particleData[wEntry][6][1] + 1
  119.             end if
  120.             if particleData[wEntry][5][2] < 10 then
  121.               particleData[wEntry][5][2] = particleData[wEntry][5][2] - 1
  122.             end if
  123.             if particleData[wEntry][4][2] > 3700 then
  124.               particleData[wEntry][4][2] = 3700
  125.             end if
  126.           2:
  127.             particleData[wEntry][5][2] = particleData[wEntry][5][2] - 2
  128.             if particleData[wEntry][4][2] > 3700 then
  129.               particleData[wEntry][4][2] = 3700
  130.             end if
  131.         end case
  132.         particleData[wEntry][5] = particleData[wEntry][5] + particleData[wEntry][6]
  133.         particleData[wEntry][4] = particleData[wEntry][4] + particleData[wEntry][5]
  134.         particleData[wEntry][3] = particleData[wEntry][3] - 1
  135.       end if
  136.       set the loc of sprite wSprite to (particleData[wEntry][4] - playerViewPoint) / 10
  137.       next repeat
  138.     end if
  139.   end repeat
  140. end
  141.